const {ccclass, property} = cc._decorator;
import Sprite from "./sprite";

@ccclass
export default class NewClass extends Sprite {

    @property
    readonly scale: number = 1;

    @property
    readonly scrollSpeed: number = 2;

    @property(cc.Node)
    anotherMap: cc.Node = null;

    @property
    screenWidth: number = 0;  
    screenHeight: number = 0;  
    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        let screenSize = cc.director.getWinSize();
        let mapSize = this.node.getContentSize();
        this.node.setScale(screenSize.width / mapSize.width, screenSize.height / mapSize.height)
        this.screenHeight = screenSize.height;
        this.screenWidth = screenSize.width
     }

    start () {

    }

    render(dt) {
        this.moveBy(dt, cc.p(0, -this.scrollSpeed));
        if (this.node.getPositionY() < -this.screenHeight) {
            this.moveTo(cc.p(0, this.anotherMap.getPositionY() +
                this.screenHeight));
        }
    }

    update(dt) {
        this.render(dt);
    }
}
